package org;

import java.util.ArrayList;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.tiled.TiledMap;
import org.Player;

public class BlockMap {
	public static TiledMap tmap;
	public static int mapWidth;
	public static int mapHeight;
	private int square[] = {1,1,15,1,15,15,1,15}; // coords for a square shaped tile
	public static ArrayList<Object> entities; // everything that gets created is added in this arraylist
	public static Player joe;

	public BlockMap(String ref) throws SlickException {
		entities = new ArrayList<Object>();
		tmap = new TiledMap(ref, "data");
		mapWidth = tmap.getWidth() * tmap.getTileWidth();
		mapHeight = tmap.getHeight() * tmap.getTileHeight();

		// scan the map01.tmx file, one tile at a time (x++ and y++ in tile)
		// 
		for (int x = 0; x < tmap.getWidth(); x++) {
			for (int y = 0; y < tmap.getHeight(); y++) {
				// zero (0) is the layer number of the map (layer 0 is the collision layer)
				int tileID = tmap.getTileId(x, y, 0);
				// tile numer 5 (tileID 5) is the collision tile for floor
				if (tileID == 5) {
					entities.add(
							new Block(x * 16, y * 16, square, "floor")
					);
				}
				// tile numer 6 (tileID 6) is the collision tile for ceilling
				if (tileID == 6) {
					entities.add(
							new Block(x * 16, y * 16, square, "ceilling")
					);
				}
				// tile numer 15 (tileID 15) is the collision tile for leftWall
				if (tileID == 15) {
					entities.add(
							new Block(x * 16, y * 16, square, "leftWall")
					);
				}
				// tile numer 16 (tileID 16) is the collision tile for rightWall
				if (tileID == 16) {
					entities.add(
							new Block(x * 16, y * 16, square, "rightWall")
					);
				}
			}
		}
		// creating Player
		entities.add(joe = new Player(200,50,"bleh"));
	}
}